package com.zyx.xunyilu.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.zyx.xunyilu.enums.LoginStatus;
import com.zyx.xunyilu.enums.RegisterStatus;
import com.zyx.xunyilu.enums.Roles;
import com.zyx.xunyilu.enums.SexEnum;
import lombok.Data;
import lombok.experimental.Accessors;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotNull;
import java.util.Date;

/**
 * @ClassName: User
 * @author: zyx
 * @E-mail: 1377631190@qq.com
 * @DATE: 2019/11/10 17:19
 */
@Data
@TableName("user")
@Accessors(chain = true)
public class User {

    @TableId(type = IdType.AUTO)
    private Integer id;

    private String  name;

    private String  password;

    private String  solt;

    private SexEnum sex;

    private String  openId;

    private String  avatar;

    private LoginStatus     status;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date    time;

    private Roles   admin;

    @Email(message = "邮箱格式错误")
    @NotNull(message = "不能为空")
    private String  email;

    private RegisterStatus  register;

    @TableField(exist = false)
    private String  token;

    /**
     * 对敏感信息进行清洗
     */
    public User clearUser() {
        this.setPassword(null).setSolt(null).setOpenId(null).setRegister(null);
        return this;
    }
}
